package com.lifeng.controller;

import com.lifeng.bean.User;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author:lifeng
 * @date:2020/5/21 18:01
 */
@RestController
public class RestDemoController {

    //不带参数的
    @RequestMapping("/rest1")
    public String test1(){
        return "string";
    }

    //带参数的
    @RequestMapping("/rest2")
    public String test2(String name,Integer age){
        return "string:name="+name+",age="+age;
    }

    //带参数的
    @RequestMapping("/rest3/{name}/{age}")
    public String test3(@PathVariable("name") String name,@PathVariable("age") Integer age){
        return "string:name="+name+",age="+age;
    }

    //
    @RequestMapping("/rest4")
    public User test4(String name,Integer age){
        User user = new User();
        user.setName(name);
        user.setAge(age);
        return user;
    }

    @RequestMapping("/rest5")
    public User test5(@RequestBody User user){
        return user;
    }
}
